package com.LLL.customer.controller;

import com.LLL.customer.model.Customer;
import com.LLL.customer.service.CustomerService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

import static java.nio.file.Files.setAttribute;
import static java.nio.file.Files.write;

@WebServlet("/register.do")
public class CurstomeRegisterController extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        //获取服务层对象
        CustomerService customerService = new CustomerService();
        //判读账号密码是否能查询到会员对象
        boolean customer = customerService.register(username,password);
        if (customer) {
            //获取session对象
//            HttpSession Session = req.getSession();
            //存储会员编号
//            Session.setAttribute("customerID", customer.getId());
            //存储用户账号
//            Session.setAttribute( "username", customer.getUser_name());

            req.getRequestDispatcher("Login.jsp").forward(req, resp);
        }else{
            req.getRequestDispatcher("register.jsp").forward(req, resp);
        }
    }
}